package com.itheima.module.controller;

import com.itheima.module.pojo.User;
import com.itheima.module.service.UserService;
import com.itheima.module.vo.Result;
import com.itheima.module.vo.ResultCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    Logger logger= LoggerFactory.getLogger(UserController.class);
    @Autowired
    private UserService userService;
    /*
    * 返回一个用户列表页面
    * */
    @RequestMapping("/findAll")
    public String findAll(Model model){
        logger.info("正在执行查询~~~");
        //准别一些数据 放入打到model里就行了
        List<User> list= userService.findAll();


        model.addAttribute("users",list);
        return "user/list";
    }



    @RequestMapping("/findAll2")
    @ResponseBody
    public List findAll2(){

        //准别一些数据 放入打到model里就行了
        List<User> list = userService.findAll();


        return list;
    }

    @RequestMapping("/findAll3")
    @ResponseBody
    public Result findAll3(){

        //准别一些数据 放入打到model里就行了
        List<User> list = userService.findAll();



        return Result.successOf(list);
    }
}
